package com.godyao.mall.pms.controller;

import java.util.Arrays;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.godyao.mall.pms.entity.BrandEntity;
import com.godyao.mall.pms.service.BrandService;
import com.godyao.mall.core.utils.PageUtils;
import com.godyao.mall.core.model.ResultMsg;

import javax.validation.Valid;


/**
 * 品牌
 *
 * @author godyao
 * @email godyao0801@qq.com
 * @date 2022-04-19 14:42:40
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("pms/brand")
public class BrandController {

    private final BrandService brandService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public ResultMsg list(@RequestParam Map<String, Object> params){
        PageUtils page = brandService.queryPage(params);

        return ResultMsg.resultSuccess(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{brandId}")
    public ResultMsg info(@PathVariable("brandId") Long brandId){
		BrandEntity brand = brandService.getById(brandId);

        return ResultMsg.resultSuccess(brand);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public ResultMsg save(@Valid @RequestBody BrandEntity brand){
		brandService.save(brand);

        return ResultMsg.resultSuccess("OK");
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public ResultMsg update(@RequestBody BrandEntity brand){
		//brandService.updateById(brand);
        brandService.updateCascade(brand);
        return ResultMsg.resultSuccess("OK");
    }

    /**
     * 修改状态
     */
    @RequestMapping("/changeStatus")
    public ResultMsg changeStatus(@RequestBody BrandEntity brand){
		brandService.updateById(brand);

        return ResultMsg.resultSuccess("OK");
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public ResultMsg delete(@RequestBody Long[] brandIds){
		brandService.removeByIds(Arrays.asList(brandIds));

        return ResultMsg.resultSuccess("OK");
    }

}
